﻿using System;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Threading;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using SysComm;
using SysOperationLayer.DBHandle;
using IPMS.Common;
using Resources;

public partial class OptProjectClassUpdate : Page, IRequiresSessionState
{
    protected override void InitializeCulture()
    {
        string strCulture = ConfigurationManager.AppSettings["DefaultCulture"].ToString();

        if (Session["Culture"] != null)
        {
            strCulture = Session["Culture"].ToString();
        }

        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(strCulture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(strCulture);
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!SysUtil.IsAdministratorOrNormalUserType())
        {
            Response.Redirect("ErrorPage/NotAllowed.aspx");
        }
        else if (!IsPostBack)
        {
            ((Label)Master.FindControl("lblMstTitle")).Text = "| " + ISitemap.MaintenanceFiles.ToString() + " | " + ISitemap.ProjectClassUpdate.ToString();

            string projectclass = Request["ProjectClass"].ToString();

            if (projectclass != "")
            {
                ProjectClassDB objDB = new ProjectClassDB();
                DataRow dr = objDB.GetItem(projectclass);
                objDB.CloseDB();

                if (dr != null)
                {
                    txtProjectClass.Text = Request["ProjectClass"].ToString();
                    txtDescription.Text = objDB.GetValue(dr, "Description");
                }
            }
       }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        ProjectClassDB objDB = new ProjectClassDB();

        if (objDB.Update(txtProjectClass.Text.Trim(), 
                            txtDescription.Text.Trim(),
                            Page.User.Identity.Name.ToString(),
                            HttpContext.Current.Request.UserHostAddress) == 0)
        {
            new LogDB(objDB.GetDB()).writeSucLog(SysUtil.m_functiong_user_manage, "Update Project Class Success! Project Class Code: " + txtProjectClass.Text);
            Jscript.Alert("Update Project Class Success!", Page);
        }
        else
        {
            new LogDB(objDB.GetDB()).writeFaileLog(SysUtil.m_functiong_user_manage, "Update Project Class Failure! Project Class Code: " + txtProjectClass.Text);
            Jscript.Alert("Update Project Class Failure!", Page);
            lblError.Text = objDB.ErrorMessage;
        }

        objDB.CloseDB();
    }
    
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("OptProjectClass.aspx");
    }
}
